<template>
	<view class="card-holder">
		<image src="https://ywtmp.hnwytkj.com/static/images/bj.png" mode="" class="bj"></image>
		<view class="card-content">
			<view class="avatar-box">
				<image :src="info.companyLogo"></image>
				<view class="right">
					<view class="name">{{info.companyName || '公司名称：未填写'}}</view>
					<view v-if="info.serviceScope" class="tag-box">
						<view v-for="(item, index) in info.serviceScope.split(',')" :key="index" class="tag">{{item}}</view>
					</view>
				</view>
			</view>
			<view class="search-box">
				<!-- <uv-input
					placeholder="前置图标"
					prefixIcon="search"
					border="none"
					prefixIconStyle="font-size: 22rpx;color: #909399"
				></uv-input> -->
				<image src="https://ywtmp.hnwytkj.com/static/images/search.png" mode=""></image>
				<input v-model="params.visiedname" type="text" placeholder="搜索姓名/企业/行业" confirm-type="search" @confirm="confirm"/>
			</view>
			<view v-if="list.length" class="list-box">
				<view class="list-item" v-for="item in list" :key="item.id" @tap="look(item)">
					<image class="avatar" :src="item.avatar"></image>
					<view class="right">
						<view class="info">
							<view class="name">{{item.visitorName}}</view>
							<view class="desc">
								<text v-for="(v, i) in item.companyImpression">
									<text v-if="i !== 0">/</text>
									<text :key="i">{{ v.text }}</text>									
								</text>								
							</view>
							<view class="phone">
								<image src="https://ywtmp.hnwytkj.com/static/images/phone.png" mode="aspectFit"></image>
								<text>{{item.phoneNumber}}</text>
							</view>
						</view>
						<view v-if="item.collectedUserId === item.collectorId" class="flag">本人</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '@/utils/http.js'
	export default {
		data() {
			return {
			  value: '',
			  params: {
				pageSize: 10,
				pageNo: 1,
				visiedname: ''
			  },
			  info: {},
			  userInfo: {},
			  list: [],
			  total: 0,
			  loading: false,
			  isEnd: false,
			  refresh: false
			}
		},
		onLoad() {
			this.getCompanyInfo()
			this.getData()
		},
		methods: {
			look(item) {
				uni.navigateTo({
					url: `/pagesA/share/card?id=${item.collectedUserId}&encrypted=${this.userInfo.level}`
				})
			},
			confirm(e) {
				this.params.pageNo = 1
				this.refresh = true
				this.getData()
			},
			loadMore() {
			  if (this.loading || this.isEnd) return;			  
			  this.params.pageNo++;
			  this.getData();
			},
			getCompanyInfo() {
				http({
					url: 'card/user-profile/get'
				}).then(res => {				
					if(res.code === 0) {
						this.info = res.data.companyProfileDO
						this.userInfo = res.data.userProfileDO
					}
				})		
			},
			getData() {
				this.loading = true;
				http({
					url: 'card/user-profile/businesscard/page',
					data: {
						...this.params
					}
				}).then(res => {
					this.loading = false;
					if(res.code === 0) {
						if (this.refresh) {
							this.list = []
						}
						res.data.list.forEach(v => {
							v.companyImpression = v.companyImpression ? JSON.parse(v.companyImpression) : []
						})
						this.list = this.list.concat(res.data.list)
						this.total = res.data.total
						if (this.list.length >= this.total) {
							this.isEnd = true
						}
					}
				})		
			}
		},
		onReachBottom() {
		    // 触发加载更多逻辑
		    this.loadMore();
		}
	}	
</script>

<style lang="scss" scoped>
	.card-holder {
		min-height: 100vh;
		background-color: #F0F0F4;
		font-family: PingFang SC;
		// background-image: url('https://ywtmp.hnwytkj.com/static/images/bj.png');
		// background-size: 100% auto;
		.bj {
			width: 100%;
			height: 431rpx;
			position: absolute;
			z-index: 1;
			left: 0;
			top: 0;
		}
		.card-content {
			padding: 50rpx 20rpx;
			position: relative;
			z-index: 9;
			.avatar-box {
				display: flex;
				align-items: center;
				image {
					width: 150rpx;
					height: 150rpx;
					background: #E3E3E3;
					border-radius: 75rpx;
				}
				.right {
					margin-left: 30rpx;
					.name {
						font-weight: bold;
						font-size: 34rpx;
						color: #FFFFFF;
					}
					.tag-box {
						display: flex;
						align-items: center;
						margin-top: 30rpx;
						.tag {
							width: 130rpx;
							height: 50rpx;
							line-height: 50rpx;
							text-align: center;
							background: rgba(255, 255, 255, 0.4);
							border-radius: 25rpx;
							font-weight: 500;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-right: 10rpx;
						}
					}
				}
			}
			.search-box {
				height: 100rpx;
				background: #FFFFFF;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				margin-top: 50rpx;
				image {
					width: 32rpx;
					height: 32rpx;
				}
				input {
					height: 100rpx;
					flex: 1;
					padding-left: 22rpx;
					font-weight: 500;
					font-size: 28rpx;
					// color: #999999;
				}
			}
			.list-box {
				background: #FFFFFF;
				border-radius: 40rpx;
				padding: 10rpx 30rpx;
				margin-top: 20rpx;
				.list-item {
					height: 182rpx;
					border-bottom: 2rpx solid #E6ECFF;
					display: flex;
					align-items: center;
					&:last-child {
						border-bottom: 0 none;
					}
					.avatar {
						width: 120rpx;
						height: 120rpx;
						background: #E3E3E3;
						border-radius: 60rpx;
					}
					.right {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding-left: 32rpx;
						flex: 1;						
						.info {
							display: flex;
							justify-content: space-between;
							flex-direction: column;
							height: 120rpx;
							.name {
								font-weight: 500;
								font-size: 28rpx;
								color: #333333;
							}
							.desc {
								font-weight: 500;
								font-size: 22rpx;
								color: #CCCCCC;
							}
							.phone {
								font-weight: bold;
								font-size: 28rpx;
								color: #333333;
								display: flex;
								align-items: center;
								image {
									margin-right: 20rpx;
									width: 24rpx;
									height: 24rpx;
								}
							}
						}
						.flag {
							width: 150rpx;
							height: 70rpx;
							line-height: 70rpx;
							text-align: center;
							background: #E6ECFF;
							border-radius: 35rpx;
							font-weight: 500;
							font-size: 28rpx;
							color: #4B73FF;
						}
					}
				}
			}
		}
	}
</style>